package com.xxkj.drugtraceability.ui.hascollected

import android.content.Intent
import android.text.Html
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.google.gson.Gson
import com.xxkj.drugtraceability.R
import com.xxkj.drugtraceability.bean.DrugInStorageBean
import com.xxkj.drugtraceability.bean.TwoItemData
import com.xxkj.drugtraceability.databinding.LayoutDrugItemBinding
import com.xxkj.drugtraceability.databinding.LayoutOneItemBinding
import com.xxkj.drugtraceability.databinding.LayoutTwoItemBinding
import com.xxkj.drugtraceability.ext.clickN
import com.xxkj.drugtraceability.ui.drugscan.DrugScanActivity

/**
 * author: zhoujingjin
 * created on: 2024/9/10 16:52
 * description:
 */
class ThreeAdapter(val action:(data:TwoItemData)->Unit):BaseQuickAdapter<TwoItemData, BaseDataBindingHolder<LayoutTwoItemBinding>>(R.layout.layout_two_item) {
    var hasData = false
    override fun convert(
        holder: BaseDataBindingHolder<LayoutTwoItemBinding>,
        item: TwoItemData
    ) {
        holder.dataBinding?.apply {
//            if (hasData){
//                btnTrace.text = "查看追溯码"
//            }else{
//                btnTrace.text = "采集追溯码"
//            }
            val buffer = StringBuffer()
            buffer.append("<font color='#666666'>")
            buffer.append("住院号:")
            buffer.append("</font>")
            buffer.append("<font color='#33333F'>")
            buffer.append(item.rxno)
            buffer.append("</font>")
            tvDetail.text = Html.fromHtml(buffer.toString())

            val buffer1 = StringBuffer()
            buffer1.append("<font color='#666666'>")
            buffer1.append("医嘱开立时间:")
            buffer1.append("</font>")
            if (!item.prescriptionTime.isNullOrEmpty()) {
                buffer1.append("<font color='#494953'>")
                if (item.prescriptionTime.length > 10) {
                    buffer1.append(item.prescriptionTime.substring(0, 10))
                } else {
                    buffer1.append(item.prescriptionTime)
                }
                buffer1.append("</font>")
            }
            tvDate.text = Html.fromHtml(buffer1.toString())
            tvContent.text = item.psnName
            tvWatch.clickN {
                action.invoke(item)
            }
//            btnTrace.clickN {
//                action.invoke(Gson().toJson(item))
//                //点击去到扫追溯码页面
//            }
        }
    }
}